package org.ms.mconf.server.springboot.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.ms.mconf.sdk.model.NodeConfig;
import org.ms.mconf.server.springboot.BaseApi;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("node")
@Api(description = "The multi data center node service api")
public class NodeApi extends BaseApi {

    @ApiOperation(value = "gets", notes = "The get all node list")
    @RequestMapping(method = RequestMethod.GET)
    public Set<NodeConfig> gets() {
        return super.nodeService().query();
    }

    @ApiOperation(value = "publish", notes = "The publish node config data")
    @ApiImplicitParam(name = "nodeConfig", value = "The Node Config Data", required = true, dataType = "NodeConfig", paramType = "body")
    @RequestMapping(method = RequestMethod.POST)
    public boolean publish(@RequestBody NodeConfig nodeConfig) {
        return super.nodeService().publish(nodeConfig);
    }

    @ApiOperation(value = "delete", notes = "The delete node config by node id")
    @ApiImplicitParam(name = "node", value = "The node id", required = true, dataType = "string", paramType = "path")
    @RequestMapping(value = "{node}", method = RequestMethod.DELETE)
    public boolean delete(@PathVariable String node) {
        return super.nodeService().delete(node);
    }

}